package com.db.bankapp.service.bank;

import com.db.bankapp.domain.bank.Account;
import com.db.bankapp.domain.bank.Bank;
import com.db.bankapp.domain.bank.Client;

/**
 * Created by Student on 18.08.2014.
 */
public class BankService {

    /**
     * Adds client to bank
     * @param bank to which add client
     * @param client to add to bank
     */
    public static void addClient(Bank bank, Client client) {
        bank.addClient(client);
    }

    /**
     * Return and prints maximum amount to withdraw in bank
     * @param bank in which to search
     * @return maximum amount to withdraw in bank
     */
    public static int printMaximumAmountToWithdraw(Bank bank) {
        // buzzy ^.^
        int max = bank.getClients().stream().map(
                (client) -> client.getAccounts().stream()
                        .map(Account::maximumAmountToWithdraw).max(Integer::compareTo).get())
                .max(Integer::compareTo).get();
        System.out.println(max);
        return max;
    }
}
